using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

using Darilek.SandcastleExtensions.Utilities;

namespace Darilek.SandcastleExtensions.Components.Configuration
{
	internal partial class MetaAttributeConfigDlg : Form
	{
		private MetaAttributeComponentConfiguration _settings;
		private string _configuration;

		public MetaAttributeConfigDlg(string configuration)
		{
				InitializeComponent();

				_settings = ConfigurationSerializer.LoadConfiguration<MetaAttributeComponentConfiguration>(configuration);

				metaAttributeBindingSource.DataSource = _settings.MetaAttributes;
		}

		public string Configuration
		{
			get { return _configuration; }
		}

		private void addAttributeButton_Click(object sender, EventArgs e)
		{
			metaAttributeBindingSource.Add(new MetaAttribute("DocSet", "Enter value here"));
			metaAttributeBindingSource.EndEdit();
			attributesGridView.Rows[attributesGridView.Rows.Count-1].Cells[0].Selected = true;

		}

		private void removeAttributeButton_Click(object sender, EventArgs e)
		{
			if (attributesGridView.SelectedRows.Count > 0)
			{
				MetaAttribute attribute = attributesGridView.SelectedRows[0].DataBoundItem as MetaAttribute;
				metaAttributeBindingSource.Remove(attribute);
				metaAttributeBindingSource.EndEdit();
			}

		}

		private void okButton_Click(object sender, EventArgs e)
		{
			_configuration = ConfigurationSerializer.SaveConfiguration<MetaAttributeComponentConfiguration>(_settings);

			this.Close();
		}

		private void attributesGridView_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
		{
			removeAttributeButton.Enabled = attributesGridView.RowCount > 0;
		}

		private void defaultButton_Click(object sender, EventArgs e)
		{
			metaAttributeBindingSource.Clear();
			metaAttributeBindingSource.Add(new MetaAttribute("DocSet", "NETFramework"));
			metaAttributeBindingSource.EndEdit();
		}

	}
}